using CodePlex.DnD4eCampaignManager.DnD4e;
using CodePlex.DnD4eCampaignManager.DnD4e.Interfaces;
using CodePlex.DnD4eCampaignManager.Presentation.ViewInterfaces;
using CodePlex.DnD4eCampaignManager.Repositories;

namespace CodePlex.DnD4eCampaignManager.Presentation
{
    public class MonsterPresenter
    {
        public MonsterPresenter(string monsterName, IMonsterView view, IMonsterRepository monsterRepository)
        {
            MonsterName = monsterName;
            View = view;
            MonsterRepository = monsterRepository;
        }

        public string MonsterName { get; set; }
        public IMonsterRepository MonsterRepository { get; set; }
        public IMonsterView View { get; set; }

        public void DisplayMonster()
        {
            View.MonsterName = MonsterName;
            if ( !MonsterRepository.GetAllNames().Contains(MonsterName) )
            {
                return;
            }
            IMonster monster = MonsterRepository.GetByName(MonsterName);
            View.Level = monster.Level;
            View.Role = monster.Role;
            View.Elite = monster.Elite;
            View.Leader = monster.Leader;
            View.Solo = monster.Solo;
            View.MonsterSize = monster.CreatureSize;
            View.Origin = monster.Origin;
            View.Keywords = monster.Keywords.ToCommaDelimitedString();
            View.HitPoints = monster.HitPointsMaximum;
            View.InitiativeModifier = monster.InitiativeModifier;
            View.ArmorClass = monster.DefenseArmorClass;
            View.FortitudeDefense = monster.DefenseFortitude;
            View.ReflexDefense = monster.DefenseReflex;
            View.WillpowerDefense = monster.DefenseWillpower;
            View.Perception = monster.SensesPerception;
            View.Senses = monster.SensesOther;
            View.Speed = monster.MovementSpeed;
            View.SpeedOther = monster.MovementSpeedOther;
            View.ActionPoints = monster.ActionPoints;
            View.SavingThrows = monster.SavingThrows;
            View.Strength = monster.AbilityStrength;
            View.Constitution = monster.AbilityConstitution;
            View.Dexterity = monster.AbilityDexterity;
            View.Intelligence = monster.AbilityIntelligence;
            View.Wisdom = monster.AbilityWisdom;
            View.Charisma = monster.AbilityCharisma;
            View.AttackPowers = monster.AttackPowers;
            View.SpecialQualities = monster.SpecialQualities;
            View.Tactics = monster.Tactics;
            View.Equipment = monster.Equipment;
            View.ExperiencePointValue = monster.ExperiencePointValue;
        }

        public void SaveMonster()
        {
            string monsterName = View.SaveAsName;
            IMonster monster = new Monster(new Abilities(), new Defenses(), new HitPoints(), new Movement(), new Senses(), new Initiative())
                                   {
                                       Name = monsterName,
                                       Level = View.Level,
                                       Role = View.Role,
                                       Elite = View.Elite,
                                       Leader = View.Leader,
                                       Solo = View.Solo,
                                       CreatureSize = View.MonsterSize,
                                       Origin = View.Origin,
                                       Keywords = View.Keywords.ToListOfStrings(),
                                       HitPointsMaximum = View.HitPoints,
                                       InitiativeModifier = View.InitiativeModifier,
                                       DefenseArmorClass = View.ArmorClass,
                                       DefenseFortitude = View.FortitudeDefense,
                                       DefenseReflex = View.ReflexDefense,
                                       DefenseWillpower = View.WillpowerDefense,
                                       SensesPerception = View.Perception,
                                       MovementSpeed = View.Speed,
                                       MovementSpeedOther = View.SpeedOther,
                                       ActionPoints = View.ActionPoints,
                                       SavingThrows = View.SavingThrows,
                                       AttackPowers = View.AttackPowers,
                                       SpecialQualities = View.SpecialQualities,
                                       Tactics = View.Tactics,
                                       Equipment = View.Equipment,
                                       AbilityCharisma = View.Charisma,
                                       AbilityConstitution = View.Constitution,
                                       AbilityDexterity = View.Dexterity,
                                       AbilityIntelligence = View.Intelligence,
                                       AbilityStrength = View.Strength,
                                       AbilityWisdom = View.Wisdom
                                   };
            MonsterName = monsterName;
            MonsterRepository.Save(monster);
            DisplayMonster();
        }
    }
}